package collectionexercise;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionOperDemo2 {
    public static void main(String[] args) {
        Collection c=new ArrayList();
        c.add("罗卜");
        c.add("白菜");
        c.add("胡萝卜");
        System.out.println("c:"+c);//[罗卜,白菜，胡萝卜]
        Collection c1=new ArrayList();
        c1.add("罗卜");
        c1.add("白菜");
        c1.add("香菜");
        c1.add("西瓜");
        System.out.println("c1:"+c1);//[罗卜，白菜，香菜，西瓜]
        c.addAll(c1);
        System.out.println("c:"+c);//[罗卜,白菜，胡萝卜,罗卜，白菜，香菜，西瓜]
        System.out.println("c1:"+c1);//[罗卜，白菜，香菜，西瓜]

        boolean b=c.containsAll(c1);
        System.out.println("c中是否包含c1:"+b);

        c.retainAll(c1);
        System.out.println("c:"+c);//[罗卜,白菜,罗卜，白菜，香菜，西瓜]
        System.out.println("c1:"+c1);//[罗卜，白菜，香菜，西瓜]

        c.removeAll(c1);
        System.out.println("c:"+c);//[]
        System.out.println("c1:"+c1);//[罗卜，白菜，香菜，西瓜]





    }
}
